﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _plants_vs_zombies
{
    class Zombie
    {
        /// <summary>
        /// 定义僵尸的rectangle
        /// </summary>
        public Rectangle Rectangle { get; set; }

        /// <summary>
        /// 定义僵尸的移动速度
        /// </summary>
        public int Speed;

        /// <summary>
        /// 僵尸的生命值
        /// </summary>
        public int zombielifenow = 15;

        /// <summary>
        /// 初始化切换图片的时间
        /// </summary>
        private DateTime changepicture = System.DateTime.Now.AddHours(-1);

        /// <summary>
        /// 定义一个选择画哪张图的布尔逻辑
        /// </summary>
        private bool pictrue = true;

        /// <summary>
        /// 定义僵尸的是否攻击bool型状态
        /// </summary>
        public bool Isattack = false;

        /// <summary>
        /// 定义一个用于切图的变量i
        /// </summary>
        private int i = 1;

        /// <summary>
        /// 初始化Zombie
        /// </summary>
        /// <param name="rec"></param>
        /// <param name="zombielifenow"></param>
        public Zombie(Rectangle rec,int zombielifenow)        
        {
            Rectangle = rec;
            //僵尸的移动速度
            Speed = -3;
        }

        /// <summary>
        /// 绘制Zombie
        /// </summary>
        /// <param name="g"></param>
        public void Draw(Graphics g)
        {
            //画变化的僵尸
            if (Isattack)
            {
                //抓植物
                if (System.DateTime.Now > changepicture)
                {
                    if (pictrue)
                    {
                        g.DrawImage(Properties.Resources.attack1, Rectangle);
                        pictrue = false;
                    }
                    else
                    {
                        g.DrawImage(Properties.Resources.attack2, Rectangle);
                        pictrue = true;
                    }
                    changepicture = System.DateTime.Now.AddSeconds(0.3);
                }
                else
                {
                    g.DrawImage(Properties.Resources.attack1, Rectangle);
                }
            }
            //没抓植物
            else
            {
                if (System.DateTime.Now > changepicture)
                {
                    if (zombielifenow<=3)
                    {
                        if (zombielifenow == 3)
                        {
                            g.DrawImage(Properties.Resources._3, Rectangle);
                        }
                        if (zombielifenow == 2)
                        {
                            g.DrawImage(Properties.Resources._2, Rectangle);
                        }
                        if (zombielifenow == 1)
                        {
                            g.DrawImage(Properties.Resources._1, Rectangle);
                        }
                    }
                    else
                    {
                        switch (i)
                        {
                            case 1:
                                g.DrawImage(Properties.Resources.僵尸1, Rectangle);
                                break;
                            case 2:
                                g.DrawImage(Properties.Resources.僵尸2, Rectangle);
                                break;
                            case 3:
                                g.DrawImage(Properties.Resources.僵尸3, Rectangle);
                                break;
                            case 4:
                                g.DrawImage(Properties.Resources.僵尸4, Rectangle);
                                break;
                            case 5:
                                g.DrawImage(Properties.Resources.僵尸5, Rectangle);
                                break;
                            case 6:
                                g.DrawImage(Properties.Resources.僵尸6, Rectangle);
                                break;
                            case 7:
                                g.DrawImage(Properties.Resources.僵尸7, Rectangle);
                                break;
                            case 8:
                                g.DrawImage(Properties.Resources.僵尸8, Rectangle);
                                break;
                            case 9:
                                g.DrawImage(Properties.Resources.僵尸9, Rectangle);
                                break;
                            case 10:
                                g.DrawImage(Properties.Resources.僵尸10, Rectangle);
                                break;
                            case 11:
                                g.DrawImage(Properties.Resources.僵尸11, Rectangle);
                                break;
                            case 12:
                                g.DrawImage(Properties.Resources.僵尸12, Rectangle);
                                break;
                            case 13:
                                g.DrawImage(Properties.Resources.僵尸13, Rectangle);
                                break;
                            case 14:
                                g.DrawImage(Properties.Resources.僵尸14, Rectangle);
                                break;
                            case 15:
                                g.DrawImage(Properties.Resources.僵尸15, Rectangle);
                                break;
                            case 16:
                                g.DrawImage(Properties.Resources.僵尸16, Rectangle);
                                break;
                            case 17:
                                g.DrawImage(Properties.Resources.僵尸17, Rectangle);
                                break;
                            case 18:
                                g.DrawImage(Properties.Resources.僵尸18, Rectangle);
                                break;
                            case 19:
                                g.DrawImage(Properties.Resources.僵尸19, Rectangle);
                                break;
                            case 20:
                                g.DrawImage(Properties.Resources.僵尸20, Rectangle);
                                break;
                            case 21:
                                g.DrawImage(Properties.Resources.僵尸21, Rectangle);
                                break;
                            case 22:
                                g.DrawImage(Properties.Resources.僵尸22, Rectangle);
                                //循环
                                i = 0;
                                break;
                            default:
                                break;
                        }                            
                    }
                    i++;
                    changepicture = System.DateTime.Now.AddSeconds(0.5);
                }
                else
                {
                    if (zombielifenow <= 3)
                    {
                        if (zombielifenow == 3)
                        {
                            g.DrawImage(Properties.Resources._3, Rectangle);
                        }
                        if (zombielifenow == 2)
                        {
                            g.DrawImage(Properties.Resources._2, Rectangle);
                        }
                        if (zombielifenow == 1)
                        {
                            g.DrawImage(Properties.Resources._1, Rectangle);
                        }
                    }
                    else
                    {
                        switch (i - 1)
                        {
                            case 0:
                                g.DrawImage(Properties.Resources.僵尸22, Rectangle);
                                break;
                            case 1:
                                g.DrawImage(Properties.Resources.僵尸1, Rectangle);
                                break;
                            case 2:
                                g.DrawImage(Properties.Resources.僵尸2, Rectangle);
                                break;
                            case 3:
                                g.DrawImage(Properties.Resources.僵尸3, Rectangle);
                                break;
                            case 4:
                                g.DrawImage(Properties.Resources.僵尸4, Rectangle);
                                break;
                            case 5:
                                g.DrawImage(Properties.Resources.僵尸5, Rectangle);
                                break;
                            case 6:
                                g.DrawImage(Properties.Resources.僵尸6, Rectangle);
                                break;
                            case 7:
                                g.DrawImage(Properties.Resources.僵尸7, Rectangle);
                                break;
                            case 8:
                                g.DrawImage(Properties.Resources.僵尸8, Rectangle);
                                break;
                            case 9:
                                g.DrawImage(Properties.Resources.僵尸9, Rectangle);
                                break;
                            case 10:
                                g.DrawImage(Properties.Resources.僵尸10, Rectangle);
                                break;
                            case 11:
                                g.DrawImage(Properties.Resources.僵尸11, Rectangle);
                                break;
                            case 12:
                                g.DrawImage(Properties.Resources.僵尸12, Rectangle);
                                break;
                            case 13:
                                g.DrawImage(Properties.Resources.僵尸13, Rectangle);
                                break;
                            case 14:
                                g.DrawImage(Properties.Resources.僵尸14, Rectangle);
                                break;
                            case 15:
                                g.DrawImage(Properties.Resources.僵尸15, Rectangle);
                                break;
                            case 16:
                                g.DrawImage(Properties.Resources.僵尸16, Rectangle);
                                break;
                            case 17:
                                g.DrawImage(Properties.Resources.僵尸17, Rectangle);
                                break;
                            case 18:
                                g.DrawImage(Properties.Resources.僵尸18, Rectangle);
                                break;
                            case 19:
                                g.DrawImage(Properties.Resources.僵尸19, Rectangle);
                                break;
                            case 20:
                                g.DrawImage(Properties.Resources.僵尸20, Rectangle);
                                break;
                            case 21:
                                g.DrawImage(Properties.Resources.僵尸21, Rectangle);
                                break;
                            case 22:
                                g.DrawImage(Properties.Resources.僵尸22, Rectangle);
                                break;
                            default:
                                break;

                        }
                    }
                }
            }
            //画血条的刷子
            SolidBrush lifeBrush = new SolidBrush(Color.Yellow);
            //画死去血条的刷子
            SolidBrush attackBrush = new SolidBrush(Color.Red);
            g.FillRectangle(lifeBrush, Rectangle.X, Rectangle.Y - 20, Rectangle.Height, 10);
            if (zombielifenow < 15)
            {
                g.FillRectangle(attackBrush, Rectangle.X, Rectangle.Y - 20, (15 - zombielifenow) * Rectangle.Height / 15, 15);
            }
        }

        /// <summary>
        /// 僵尸的移动函数
        /// </summary>
        public void Move() 
        {           
                this.Rectangle = new Rectangle(Rectangle.X + Speed, Rectangle.Y, Rectangle.Width, Rectangle.Height);
            Isattack = false;
        }

        /// <summary>
        /// 僵尸的反移动函数
        /// </summary>
        public void MoveBack()
        {
                this.Rectangle = new Rectangle(Rectangle.X-Speed, Rectangle.Y, Rectangle.Width, Rectangle.Height);
            Isattack = true;
        }
    }
}
